package com.kust.smarhome.background.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.query.MPJQueryWrapper;
import com.kust.smarhome.background.common.dto.OrderFormInfoDto;
import com.kust.smarhome.background.common.vo.OrderFormVo;
import com.kust.smarhome.background.mapper.OrderFormMapper;
import com.kust.smarhome.background.mapper.UserMapper;
import com.kust.smarhome.background.model.OrderForm;
import com.kust.smarhome.background.service.IOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-31
 */
@Service
public class OrderFormServiceImpl extends ServiceImpl<OrderFormMapper, OrderForm> implements IOrderFormService {

    @Autowired
    private OrderFormMapper orderFormMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<OrderFormInfoDto> getOrderFormInfo(Page<OrderFormInfoDto> page, OrderFormVo orderFormVo) {
        /*id username money address created state*/
        IPage<OrderFormInfoDto> dtoPage = orderFormMapper.selectJoinPage(page, OrderFormInfoDto.class,
                new MPJQueryWrapper<OrderForm>()
                        .select("t.id","t.money", "t.address_id as address", "t.money","t.courier_number as courier", "t.created", "t.state")
                        .select("u.username")
                        .leftJoin("user u on t.user_id = u.id")
                        .like(StrUtil.isNotBlank(orderFormVo.getId()), "t.id", orderFormVo.getId())
                        .eq(orderFormVo.getType() != 10, "t.state", orderFormVo.getType())
        );

        return (Page<OrderFormInfoDto>) dtoPage;
    }

}
